package com.itheima.health.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.dao.CheckItemMapper;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckItemService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
@Slf4j
public class CheckItemServiceImpl implements CheckItemService {
    @Autowired
    private CheckItemMapper checkItemMapper;

    /**
     * @Author: 位帅帅
     * @Date: 10:58 2021/1/5
     * @Params: [queryPageBean]
     * @RerurnType: com.itheima.health.entity.PageResult
     * @Description: 分页查询检查项
     */
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        log.info("[检查项-分页查询]param: {}", queryPageBean);
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        Page<CheckItem> page = checkItemMapper.findPage(queryPageBean.getQueryString());
        PageResult pageResult = new PageResult(page.getTotal(), page.getResult());
        log.info("[检查项-分页查询]result: {}", pageResult);
        return pageResult;
    }

    /**
     * @Author: 位帅帅
     * @Date: 11:45 2021/1/5
     * @Params: [checkItem]
     * @RerurnType: void
     * @Description: 添加检查项
     */
    @Override
    public void add(CheckItem checkItem) {
        log.info("[检查项-添加]param: {}", checkItem);
        checkItemMapper.insertSelective(checkItem);
    }

    /**
     * @Author: 位帅帅
     * @Date: 11:55 2021/1/5
     * @Params: [id]
     * @RerurnType: void
     * @Description: 删除检查项
     */
    @Override
    public void delete(Integer id) {
        log.info("[检查项-删除]param: {}", id);
        checkItemMapper.deleteByPrimaryKey(id);
    }

    /**
     * @Author: 位帅帅
     * @Date: 12:08 2021/1/5
     * @Params: [id]
     * @RerurnType: com.itheima.health.pojo.CheckItem
     * @Description: 根据id查询检查项
     */
    @Override
    public CheckItem findById(Integer id) {
        log.info("[检查项-id查询]param: {}", id);
        CheckItem checkItem = checkItemMapper.selectByPrimaryKey(id);
        log.info("[检查项-id查询]result: {}", checkItem);
        return checkItem;
    }

    /**
     * @Author: 位帅帅
     * @Date: 12:14 2021/1/5
     * @Params: [checkItem]
     * @RerurnType: void
     * @Description: 编辑检查项
     */
    @Override
    public void edit(CheckItem checkItem) {
        log.info("[检查项-编辑]param: {}", checkItem);
        checkItemMapper.updateByPrimaryKeySelective(checkItem);
    }

    /**
     * @Author: 位帅帅
     * @Date: 15:29 2021/1/5
     * @Params: []
     * @RerurnType: java.util.List<com.itheima.health.pojo.CheckItem>
     * @Description: 查询全部检查项
    */
    @Override
    public List<CheckItem> findAll() {
        List<CheckItem> list = checkItemMapper.selectAll();
        log.info("[检查项-查询全部]result: {}",list);
        return list;
    }
}
